{include file='Public/header' /}
<div class="layui-layout layui-layout-admin">
{include file='Public/head' /}	
{include file='Public/side' /}
<div class="layui-body"> 
{include file='Public/crumbs' /}
	<!-- 内容主体区域 -->
	<div class="shu-body">
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12 layui-col-xs12">
					<form id="export-form" class="layui-form" method="post">
						<table lay-even class="layui-table">
							<colgroup>
							<col>
							</colgroup>
							<thead>
								<tr>
								<th>备份名称</th>
                                <th>卷数</th>
                                <th>压缩</th>
                                <th>数据大小</th>
                                <th>备份时间</th>
                                <th>状态</th>
                                <th>操作</th>
								</tr>
							</thead>
							<tbody>
							{volist name="list" id="data"}
							<tr>
								<td>{$data.time|date='Ymd-His',###}</td>
								<td>{$data.part}</td>
								<td>{$data.compress}</td>
								<td>{$data.size|format_bytes}</td>
								<td>{$key}</td>
								<td>-</td>
								<td>
								<a class="layui-btn layui-btn-small db-import"  href="{:url('import?time='.$data['time'])}">还原</a>
								 
								<a class="layui-btn layui-btn-small layui-btn-danger del_btn"  href="javascript:;" nickname="{$data.time|date='Ymd-His',###}" val="{:url('del?time='.$data['time'])}">删除</a> 
								 
								</td>
							</tr>
							{/volist}
							</tbody>
						</table>
						<a href="{:url('Database/backup')}" class="layui-btn layui-btn-danger" lay-submit>数据备份</a>
					</form>
				</div>
			</div>
		</div>
	</div>
	<!-- 内容主体区域 END--> 
</div>
{include file='Public/footer' /} 
<script>
layui.use('form',function(){
  var form = layui.form,
  jq = layui.jquery;
  
  jq('.del_btn').click(function(){
	var name = jq(this).attr('nickname');
    var url = jq(this).attr('val');
    layer.confirm('确定删除【'+name+'】备份?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.get(url,function(data){
        if(data.code == 1){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else if(data.code == 0){
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });   
  });
  
  
})
</script>
<script type="text/javascript">
    $(".db-import").click(function () {
        var self = this, code = ".";
        $.get(self.href, success, "json");
        window.onbeforeunload = function () {
            return "正在还原数据库，请不要关闭！"
        }
        return false;

        function success(data) {
			//console.log(data);
            if (data.code) {
                if (data.gz) {
                    data.msg += code;
                    if (code.length === 5) {
                        code = ".";
                    } else {
                        code += ".";
                    }
                }
                $(self).parent().prev().text(data.msg);
                if (data.data.part) {
                    $.get(self.href,
                            {"part": data.data.part, "start": data.data.start},
                            success,
                            "json"
                    );
                } else {
                    window.onbeforeunload = function () {
                        return null;
                    }
                }
            } else {
                alert(data.msg, 'alert-error');
            }
        }
    });
</script>
